package com.srxz.mobilepharmacy.repository;

import com.srxz.mobilepharmacy.entity.view.VwMrStk;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.math.BigInteger;
import java.util.List;

@Repository
public interface VwMrStkRepository extends JpaRepository<VwMrStk, Integer> {
    @Query(value = "select new com.srxz.mobilepharmacy.entity.view.VwMrStk(" +
            "stk.aid, stk.mrn, stk.ad, stk.edt, stk.mid," +
            " stk.gn, stk.wn, stk.made, stk.spr, stk.sps," +
            " stk.utr, stk.uts, stk.utfac, stk.bn, stk.vdate," +
            " stk.quan, stk.pri, stk.prr, stk.idate,stk.adfn," +
            " stk.dpra, stk.dprr, stk.dprt, stk.dprm, stk.base," +
            " stk.base_cl, stk.sk, stk.sty, stk.bus, stk.rtm," +
            " stk.afn, stk.cond, stk.spec) from VwMrStk stk" +
            "   where stk.aid=?1 and stk.mid=?2 and stk.mrn = ?3 order by stk.quan desc")
    public List<VwMrStk> findStk(BigInteger aid, Integer mid, Integer mrn);

    @Query(value = "select new com.srxz.mobilepharmacy.entity.view.VwMrStk(" +
            "stk.aid, stk.mrn, stk.ad, stk.edt, stk.mid," +
            " stk.gn, stk.wn, stk.made, stk.spr, stk.sps," +
            " stk.utr, stk.uts, stk.utfac, stk.bn, stk.vdate," +
            " stk.quan, stk.pri, stk.prr, stk.idate,stk.adfn," +
            " stk.dpra, stk.dprr, stk.dprt, stk.dprm, stk.base," +
            " stk.base_cl, stk.sk, stk.sty, stk.bus, stk.rtm," +
            " stk.afn, stk.cond, stk.spec) from VwMrStk stk" +
            "   where stk.aid=?1 and stk.mid=?2 and stk.mrn = ?3 and stk.quan != 0 order by stk.quan desc")
    public List<VwMrStk> findStkZero(BigInteger aid, Integer mid, Integer mrn);

}
